package zy.gongxiang.pucharse.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import zy.gongxiang.pucharse.dataobject.Udc;

import java.util.List;

/**
 * @Auther: zhangy
 * @Date: 2018/9/17 11:06
 * @Description:
 */


public interface UdcRepository extends JpaRepository<Udc,String> {


    @Query("select distinct a.descriptionOne from  Udc a where a.productCode = ?1 and a.userdefinedCode = ?2")
    String findDescription(String productcode,String definedcode);

    List<Udc> findByProductCodeAndUserdefinedCode(String productcode,String definedcode);

    List<Udc> findByDetailCode(String detailcode);

    List<Udc> findByDetailMessage(String detailMessage);

    //依据明细类编码进行模糊查询
    @Query("select a from Udc a where a.detailCode like %?1%")
    List<Udc> findByDetailCodeSqlObject(String detailCode);

    //依据明细类描述进行模糊查询或查询
    @Query(value = "select * from md_udc where detail_message like %?1%",nativeQuery = true)
    List<Udc> findBysql(String detailMessage);

    //更新明细代码和明细说明
    //@Transactional  方法调用时必须在事务中进行
    @Modifying
    @Query("update Udc a set a.detailCode = ?1,a.detailMessage = ?2 where a.detailCode = ?3")
    public void updateDetailCodeAndDetailMessage(String code,String msg,String upCode);

    //查询产品码和用户自定义码
    @Query("select distinct a.productCode,a.userdefinedCode,a.descriptionOne from  Udc a")
    List<String[]> findAllsql();

    //查询
    @Query("select distinct a.detailCode,a.detailMessage,a.detailDescription from  Udc a where a.productCode = ?1 and a.userdefinedCode = ?2")
    List<String[]> findDetailSql(String productcode,String definedcode);

}
